package com.gopay.common.cps.dao.sms.impl;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.cps.dao.sms.SmsMassDAO;
import com.gopay.common.domain.sms.SmsMass;
import org.springframework.stereotype.Repository;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import java.sql.SQLException;
import java.util.List;


/*
 * Copyright (c) 2016. www.gopay.com.cn Inc.All rights reserved.
 * 文件名称 : SmsMassDAOImpl
 * 创建日期 : 17/6/19 18:54
 * Author  : baiyunpeng
 */
@Repository
public class SmsMassDAOImpl extends BaseDAOImpl<SmsMass,String> implements SmsMassDAO {
    @Override
    public Object bathInsertSmsMass(final List<SmsMass> smsMassList) {
        return this.getHibernateTemplate().execute(new HibernateCallback() {
            @Override
            public Object doInHibernate(Session session) throws HibernateException, SQLException {
                for (int i = 0; i < smsMassList.size(); i++) {
                    session.save(smsMassList.get(i));
                    if (i % 100 == 0) {
                        session.flush();
                        session.clear();
                    }
                }
                return null;
            }
        });
    }
}
